<?php
define('prfix_scene', 'qrscene_');
class qrcode {
	public static function showNotLimitQRCode($id) {
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		
		$QRModel = M("qrcode");
		$where['id'] = array('eq',$id);
		$sceneId = $QRModel->where($where)->getField('sceneId');
		Session::switchCustomer($customerId);
		
		if ($sceneId) {
			$qr = R('QRCode/createQRCode', array('QR_SCENE', $sceneId));
			if ($qr != NULL) {
				$resultQr = $QRModel->where($where)->setField('ticket', $qr->ticket);
				if ($resultQr !== false) {
					$result["qrcode"] = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . $qr->ticket;
					$expireTime = (int)$qr->expire_seconds / 60;
					$result["expireTime"] = $expireTime;
					Output::instance()->module("qrcode", "qrcode")->object($result);
				} else {
					Output::instance()->resultCode(code_sql_error);
				}
			} 
		} else {
			Output::instance()->resultCode(code_qr_not_exist);
		}
	}
	
	public static function scanFromSubscribe($message) {
		$ticket = $message->ticket;
		if ($ticket == '') {
			return;
		}
		
		$sceneId = $message->eventKey;
		$sceneId = substr($sceneId, strlen(prfix_scene));
		return self::scan($sceneId, $ticket, $message);
	}
	
	public static function scanFromScan($message) {
		$sceneId = $message->eventKey;
		$ticket = $message->ticket;
		return self::scan($sceneId, $ticket, $message);
	}
	
	private static function scan($sceneId, $ticket, $message) {
		self::writeScanLog($sceneId, $ticket, $message->fromUserName);
		
		set_point_by_point_type(module_handle_qrcode, $message->fromUserName,false,  '二维码：' . $sceneId);
		
		
		if(!empty($message->accessTag) && !empty($message->fromUserName)){	
			 setAccessTags($message->accessTag,$message->fromUserName,module_handle_qrcode, $message->id);
		}
		
		
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		
		$QRModel = M("qrcode");
		$where["sceneId"] = $sceneId;
		$where["ticket"] = $ticket;
		$qrcode = $QRModel->where($where)->find();
// 		Log::write($QRModel->getLastSql());
		if (!$qrcode) {
//		    Log::write("not found qrcode");
			Session::switchCustomer($customerId);
			return;
		}
		
		Session::switchCustomer($customerId);
		
		if ($qrcode["accessTag"] != NULL) {
		//	set_accesstag($qrcode["accessTag"], $message->fromUserName, module_handle_qrcode, $qrcode["id"]);
		}
		
		if ($qrcode["actionInfo"] != '')  {
			$params = new stdClass();
			$params->keyword = $qrcode["actionInfo"];
			$params->message = $message;
			Module::callModule('keyword', NULL, 'sendNewsCode', $params);
		}
		$module = $qrcode["module"];
		if(!$module){   //  && $module != 0
		    return '';
        }

		switch ($module) {
			case module_handle_inviteCodeInput:
				$mid = $qrcode["moduleId"];
				if ($mid == 0) {
					Log::write("qrcode scan no mid");
					return;
				}
				return self::handleInviteCode($mid,$qrcode["id"], $message);
				break;
			case module_handle_wxrouter:
				self::handleWxRouter($qrcode["sceneId"], $message);
				break;
			default:
				$params = new stdClass();
				$params->id = $qrcode["moduleId"];
				$params->message = $message;
				$params->codeId = $qrcode["id"];
				return Module::callModule($module, NULL,$qrcode["method"], $params);
		}
	}
	
	private function handleInviteCode($mid, $qrcodeId, $message) {
		$materialModel = M("Material");
		$where["id"] = $mid;
		$material = $materialModel->where($where)->find();
		Log::write($materialModel->getLastSql());
		if (!$material) {
			Log::write("qrcode scan not find material");
			return;
		}
		
		$us = UserStatus::create($message->fromUserName, $material->id);
		UserStatus::begin($us);
		
		$us->status = '1';
		$us->reserve1 = module_handle_qrcode;
		UserStatus::update($us);
		
		$InviteCode = M("module_obtain_invite_code");
		// TODO:暂时使用该方式，应当用groupId判断
		$whereInvite["materialId"] = $mid - 1;
		$whereInvite["qrcodeId"] = $qrcodeId;
		//$whereInvite["fromUserName"] = $message->fromUserName;
		$message->content = $InviteCode->where($whereInvite)->getField('code');
		Log::write($InviteCode->getLastSql());
		
		$material = (object)$material;
		return Module::doModule(module_handle_inviteCodeInput, $message, $material, $us);
	}
	
	private function handleWxRouter($sceneId, $message, $mediaId = 0) {
		$customerId = Session::$user["customerId"];
		
		Session::switchCustomer(0);
        /**
         * LLyeap_wx_customer修改
         */
        /***** LLyeap_delete *****/
//		$CustomerModel = M("customer");
//		$where["id"] = $customerId;
//		$customer = $CustomerModel->where($where)->find();
        /*****  *****/
        $IndMediaInfo_Model = M('ind_media_info');
        if ($mediaId > 0) { // 如果拿到了$mediaId, 则通过id来筛选
            $where_info = ['cid' => $customerId, 'id' => $mediaId];
        } else {        // 如果没有$mediaId, 则拿这个cid下默认的账号, 即default = 1的, 只有一个
            $where_info = ['cid' => $customerId, 'isDefault' => 1];
        }
        $customer = $IndMediaInfo_Model->where($where_info)->find();

		Session::switchCustomer($customerId);
		if (!$customer) {
			Output::instance()->resultCode(code_user_not_exist);
			return;
		}
		
// 		$result["number"] = $sceneId;
// 		$result["appId"] = $customer["appid"];
// 		$result["openId"] = $message->fromUserName;
// 		Output::instance()->object($result);
		Log::write('scan from wx router sceneid:' . $sceneId. ',appid:' . $customer["appid"] . 
				',openid:' . $message->fromUserName);
		
		
		$params = "number=" . $sceneId . "&appId=" . $customer["appid"] . "&openId=" .$message->fromUserName;
// 		Log::write($params);
		//$params = urldecode(json_encode($result));
		$url='http://www.iammig.com/wxrb_ptcodeevrst';
// 		Log::write($url);
		
		
		$ch = curl_init($url) ;
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		// 设置curl允许执行的最长秒数为5
		curl_setopt($ch, CURLOPT_TIMEOUT, 5);
		
		$result = curl_exec($ch);
		curl_close($ch);
		Log::write($result);
		
		//$result = json_decode($result);
		
	}
	
	
	/*
	 * 添加扫码记录，和扫码统计数
	 */
	private function writeScanLog($sceneId, $ticket, $userName,$retype = null) {
		
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		$QRModel = M("qrcode");
		$posterModel = M("poster");
		$where["sceneId"] = $sceneId;
		if(empty($retype)){
            $where["ticket"] = $ticket;
        }
        if($retype == 1){
            $posterId = $QRModel->alias('a')->where(['sceneId'=> $sceneId])->join("wx_module_user_poster as b on a.moduleId = b.id")->getField('b.posterId');
            $posterModel->where(['id' => $posterId])->setInc('pv');

        }
		$where["fromCustomerId"] = $customerId;
		$actionName = $QRModel->where($where)->getField('actionName');
		
		// 扫码统计数
		$QRModel->where($where)->setInc('scanCount');
		
		// 用户没有扫过码则添加扫码人次数
		$LogModel = M("qrcode_scan_log");
		$logWhere["sceneId"] = $sceneId;
        $logWhere["fromCustomerId"] = $customerId;
		$logWhere["fromUserName"] = $userName;
		$hasScan = $LogModel->where($logWhere)->find();
		if (!$hasScan) {
			$QRModel->where($where)->setInc('scanUserCount');
		}
		
		if ($actionName && ($actionName == QR_URL || $actionName == QR_LIMIT_SCENE||$actionName == QR_LIMIT_STR_SCENE)) { // only write log for limit scene
			$data["sceneId"] = $sceneId;
			$data["fromCustomerId"] = $customerId;
			$data["fromUserName"] = $userName;
			$data["createTime"] = date("Y-m-d H:i:s");
			$LogModel->add($data);
		}
		
		Session::switchCustomer($customerId);
	}
	 //处理用户二维码登录事件
	 public static function login($message) {

	 	/**1.数据库模型、数据采集*/
	 	Session::switchCustomer(0);
        $login = M('qrcode_login');
        $user = M('customer_user');
        $qrcode = M('qrcode');
        $ticket = $message->ticket;
        $customerId = $qrcode->field('FromCustomerId')->where("ticket='$ticket'")->find();
        $customerId = $customerId['FromCustomerId'];
        Session::switchCustomer($customerId);

        /**2.数据保存*/
        $login->create();
        $login->ticket = $message->ticket;
        $login->customerId = $customerId;
        $login->createTime = date('Y-m-d H:i:s',time());
        $login->openId = $message->fromUserName;
        //获得刚扫描的反馈信息id
        $loginId = $login->add();
        //判断是否是内部用户
        $data_where['agent'] = array(array("EQ",'insideUser'),array("EQ",'business'),'OR');
        $data_where['customerId'] = $customerId;
        $result = $user->field('uopenId')->where($data_where)->select();
        Log::write('Log打印userId语句1'.$user->getLastSql());
        $count = count($result);
        $arr = [];
        for ($i=0;$i<$count;$i++)
        {
            $arr[] = $result[$i]['uopenId'];
        }
        $openId = $login->field('openId')->where("id=$loginId")->find();
        $openId = $openId['openId'];

        /**3.数据返回*/
        //判断在某一确定的cid下是否存在此用户的openid
        if(in_array($openId,$arr)){
        	$data_where['uopenId'] = $openId;
            $userId = $user->field('id')->where($data_where)->find();
            Log::write('Log打印userId语句2'.$user->getLastSql());
            $data['success'] = 1;
            $data['userId'] = $userId['id'];
            $result = $login->where("id=$loginId")->save($data);
            $userName = $message->fromUserName;
            WeixinApi::sendServiceMsg($userName, "text", "恭喜您登录成功，记得以后多多使用二维码登录哦");
        }else{
        	$data['success'] = 2;
            $result = $login->where("id=$loginId")->save($data);
            $userName = $message->fromUserName;
            WeixinApi::sendServiceMsg($userName, "text", "登录失败，您尚未绑定二维码登录");
        }
    }
    //用户绑定二维码登录事件
    public static function bindQRcodeLogin($message) {
    	/**1.参数获取*/
        $userName = $message->fromUserName;
        $ticket = $message->ticket;
        $customerId = Session::$user["customerId"];

        /**2.数据库模型*/
        Session::switchCustomer(0);
        $user = M('customer_user');
        $qrcode = M('qrcode');
        $bind = M('qrcode_bind');
        Session::switchCustomer($customerId);
        $weixin = M('user_weixin_info');

        /**3.数据查询*/
        //根据之前存储的信息获得userId
        $weixinInfo = $weixin->field('nickname,headimgurl')->where("openid='$userName'")->find();
        $qrcode = $qrcode->field('name')->where("ticket='$ticket'")->find();
        $name = $qrcode['name'];
        $name = explode("_",$name);
        $userId = $name[0];
        $openInfo = $user->field('uopenId,fullName,profileUrl,agent')->where("id=$userId")->find();
        $openId = $openInfo['uopenId'];
        //判断ticket所对应的bindId
        $bindId = $bind->field('id')->where("ticket='$ticket'")->find();

        /**4.数据返回*/
        //判断之前是否已经绑定
        if ($openId){
            if ($openInfo['agent'] == 'writer'){
                if (!$openInfo['fullName']){
                    $data['fullName'] = $weixinInfo['nickname'];
                }
                $data['wxName'] = $weixinInfo['nickname'];
                if (!$openInfo['profileUrl']){
                    $data['profileUrl'] = $weixinInfo['headimgurl'];
                }
                $data['uopenId'] = $userName;
                $result = $user->where("id=$userId")->save($data);
                $content_sql = $user->getLastSql();
                R('Log/add',array('accountSetting','132','账号设置',op_update,$content_sql,'用户绑定二维码登录'));
                if ($result !== false){
                    $qrcodeInfo['success'] = 1;
                    $qrcodeInfo['openId'] = $userName;
                    $qrcodeInfo['createTime'] = date('Y-m-d H:i:s',time());
                    $bindId = $bindId['id'];
                    $bind->where("id=$bindId")->save($qrcodeInfo);
                    WeixinApi::sendServiceMsg($userName, "text", "恭喜您，绑定成功，可以开启二维码登录模式");
                }else {
                    $qrcodeInfo['success'] = 2;
                    $bindId = $bindId['id'];
                    $qrcodeInfo['createTime'] = date('Y-m-d H:i:s',time());
                    $bind->where("id=$bindId")->save($qrcodeInfo);
                    WeixinApi::sendServiceMsg($userName, "text", "绑定失败，记得刷新重试哦");
                }
            }else{
                $qrcodeInfo['success'] = 3;
                $qrcodeInfo['openId'] = $userName;
                $bindId = $bindId['id'];
                $bind->where("id=$bindId")->save($qrcodeInfo);
                WeixinApi::sendServiceMsg($userName, "text", "已经绑定成功无需重新绑定");
            }
        }else{
        	if ($openInfo['agent'] == 'business' || $openInfo['agent'] == 'insideUser'){
        		$data_user['customerId'] = $customerId;
		        $data_user['uopenId'] = $userName;
		        $data_user['agent'] = array(array("EQ",'insideUser'),array("EQ",'business'),'OR');
        	}else{
        		$data_user['customerId'] = $customerId;
		        $data_user['uopenId'] = $userName;
		        $data_user['agent'] = array(array("NEQ",'insideUser'),array("NEQ",'business'),'AND');
        	}
	        $userInfo = $user->where($data_user)->find();
	        if ($userInfo){
	        	$qrcodeInfo['success'] = 4;
	        	$qrcodeInfo['openId'] = $userName;
	        	$bindId = $bindId['id'];
	        	$bind->where("id=$bindId")->save($qrcodeInfo);
	            WeixinApi::sendServiceMsg($userName, "text", "此微信已经绑定其他账号，不可重复绑定");
	        }else{
	        	if (!$openInfo['fullName']){
        		$data['fullName'] = $weixinInfo['nickname'];
	        	}
	        	$data['wxName'] = $weixinInfo['nickname'];
	        	if (!$openInfo['profileUrl']){
	        		$data['profileUrl'] = $weixinInfo['headimgurl'];
	        	}
	        	$data['uopenId'] = $userName;
		        $result = $user->where("id=$userId")->save($data);
		        $content_sql = $user->getLastSql();
		        R('Log/add',array('accountSetting','132','账号设置',op_update,$content_sql,'用户绑定二维码登录'));
		        if ($result !== false){
		        	$qrcodeInfo['success'] = 1;
		        	$qrcodeInfo['openId'] = $userName;
		        	$qrcodeInfo['createTime'] = date('Y-m-d H:i:s',time());
		        	$bindId = $bindId['id'];
		        	$bind->where("id=$bindId")->save($qrcodeInfo);
	 	            WeixinApi::sendServiceMsg($userName, "text", "恭喜您，绑定成功，可以开启二维码登录模式");
		        }else {
		        	$qrcodeInfo['success'] = 2;
		        	$bindId = $bindId['id'];
	                $qrcodeInfo['createTime'] = date('Y-m-d H:i:s',time());
		        	$bind->where("id=$bindId")->save($qrcodeInfo);
		            WeixinApi::sendServiceMsg($userName, "text", "绑定失败，记得刷新重试哦");
		        }
	        } 	
        }
    }


    //用户扫描二维码注册事件
    public static function register($message) {
    	log::write("用户注册二维码回调到此处");
    	
        /**1.参数获取*/
        $userName = $message->fromUserName;
        $ticket = $message->ticket;

        /**2.数据库模型*/
        Session::switchCustomer(0);
        $user = M('customer_user');
        $qrcode = M('qrcode');
        $register = M('qrcode_register');
        $ggUser = M('gg_user');

        /**3.数据查询*/
        //根据之前存储的信息获得customerId
        $qrcodeInfo = $qrcode->field('fromCustomerId, name')->where("ticket='$ticket'")->find();
        $customerId = $qrcodeInfo['fromCustomerId'];
        Session::switchCustomer($customerId);
        $weixin = M('user_weixin_info');

        //如果action_name 的前11位是手机号则是通过手机号注册补全过来的
        if(is_numeric(substr($qrcodeInfo['name'],0,11))){
            $hasBind['uopenId'] = $userName;
            $hasBind['agent'] = array(array("NEQ",'business'),array('NEQ','insideUser'),"AND");
            $bindFalg = $user->where($hasBind)->find();
            if($bindFalg){
                $data['success'] = 4;
                $register->where("ticket='$ticket'")->save($data);
                WeixinApi::sendServiceMsg($userName, "text", "此微信号已被绑定");
                return ;
            }
            $phone = substr($qrcodeInfo['name'],0,11);
        }

        //查询用户是否之前注册过
        $data_user['customerId'] = $customerId;
        $data_user['uopenId'] = $userName;
        $data_user['agent'] = array(array("NEQ",'business'),array('NEQ','insideUser'),"AND");
        $userInfo = $user->field('id')->where($data_user)->find();

        if ($userInfo){
            log::write("用户注册二维码回调到此处:y用户已存在直接登录".json_encode($userInfo));

            // 判断 gg_user 表是否已创建
            $ggWhere['cid'] = 3;
            $ggWhere['cuid'] = $userInfo['id'];
            $isGgUser = $ggUser->where($ggWhere)->find();

    	 	$data['userId'] = $userInfo['id'];
	        $data['openId'] = $userName;
            $data['success'] = empty($isGgUser) ? 1 : 3;
	        $data['createTime'] = date('Y-m-d H:i:s',time());
	        $register->where("ticket='$ticket'")->save($data);
	        WeixinApi::sendServiceMsg($userName, "text", "恭喜您登录成功，记得以后多多使用二维码登录哦");
        }else{
        	//在user表里添加新用户，同时在微信表里获得用户的基本信息并存入表结构
        	$weixinInfo = $weixin->field('nickname,headimgurl,country,province,city,phone')->where("openid='$userName'")->find();

            // 查询该 昵称是否在平台已存在
            $nickname = self::wxNameFilter($weixinInfo['nickname']);
            $loginName = $user->field('count(*) as count')->where("loginName='$nickname'")->find();
            if($loginName['count']){
                $nickname = $nickname.'_'.time();
            }

	        $user->create();
	        $user->customerId = $customerId;
	        $user->fullName = $nickname;
	        $user->wxName = $weixinInfo['nickname'];
	        $user->profileUrl = $weixinInfo['headimgurl'];
	        $user->email = '';
	        $user->loginName = $nickname;
	        $user->password =  null;
	        $user->agent = 'writer';
	        $user->address = $weixinInfo['country'].$weixinInfo['province'].$weixinInfo['city'];
	        $user->status = 'open';
	        $user->phone = isset($phone) ? $phone : $weixinInfo['phone'];
	        $user->uopenId = $userName;
	        $user->openid = $userName;
	        $newId = $user->add();

	        /**4.数据返回*/
	        if ($newId){
	        	log::write("用户注册二维码回调到此处:新建用户".$newId);
	        	$content_sql = $user->getLastSql();
                //R('Log/add',array('accountSetting','132','账号设置',op_add,$content_sql,'用户使用二维码扫描注册'));
	        	//完善扫描登录信息
		        $data['userId'] = $newId;
		        $data['openId'] = $userName;
		        $data['success'] = 1;
		        $data['createTime'] = date('Y-m-d H:i:s',time());
		        //判断ticket所对应的注册id,将userid信息存入
		        $register->where("ticket='$ticket'")->save($data);
	            WeixinApi::sendServiceMsg($userName, "text", "恭喜您注册成功，记得以后多多使用二维码登录哦");
	        }else{
	        	log::write("用户注册二维码回调到此处:新建用户失败");
	            $data['userId'] = '';
	            $data['openId'] = $userName;
	            $data_error['success'] = 2;
	            $data['createTime'] = date('Y-m-d H:i:s',time());
	            $register->where("ticket='$ticket'")->save($data_error);
	            WeixinApi::sendServiceMsg($userName, "text", "注册失败，请重试");

	        }
        }
    }

    /**
     * 微信 昵称 特殊字符串过滤
     */
    public static function wxNameFilter($str)
    {
        if ($str) {
            $name = $str;
            $name = preg_replace('/\xEE[\x80-\xBF][\x80-\xBF]|\xEF[\x81-\x83][\x80-\xBF]/', '', $name);
            $name = preg_replace('/xE0[x80-x9F][x80-xBF]‘.‘|xED[xA0-xBF][x80-xBF]/S', '?', $name);
            $return = json_decode(preg_replace("#(\\\ud[0-9a-f]{3})#ie", "", json_encode($name)));
        } else {
            $return = 'gg_'. rand(1000,99999);
        }
        return $return;
    }

    /**
     * 用户扫描二维码进行解绑微信操作
     * @param array $message   微信扫码返回信息
     */
    public static function qrcodeUnbind($message) {
        /**1.参数获取*/
        $userName = $message->fromUserName;
        $ticket = $message->ticket;
        $customerId = Session::$user["customerId"];

        /**2.数据库模型*/
        Session::switchCustomer(0);
        $user = M('customer_user');
        $qrcode = M('qrcode');
        $unbind = M('qrcode_unbind');
        Session::switchCustomer($customerId);

        /**3.数据查询*/
        //根据之前存储的信息获得userId
        $qrcode = $qrcode->field('name')->where("ticket='$ticket'")->find();
        $name = $qrcode['name'];
        $name = explode("_",$name);
        $userId = $name[0];
        $openId = $user->field('uopenId,agent')->where("id=$userId")->find();
        $agent = $openId['agent'];
        $openId = $openId['uopenId'];
        //判断ticket所对应的bindId
        $unbindId = $unbind->field('id')->where("ticket='$ticket'")->find();

        /**4.数据返回*/
        //判断之前是否已经绑定
        if ($openId){
            if ($openId !== $userName){
                $qrcodeInfo['success'] = 3;
                $qrcodeInfo['openId'] = $userName;
                $unbindId = $unbindId['id'];
                $unbind->where("id=$unbindId")->save($qrcodeInfo);
                WeixinApi::sendServiceMsg($userName, "text", "您不是此账号绑定者，无权解绑此账号");
            }else{
                if ($agent !== 'writer') {
                    $data['uopenId'] = '';
                    $data['openId'] = '';
                    $data['wxName'] = '';
                    $result = $user->where("id=$userId")->save($data);
                    $content_sql = $user->getLastSql();
                    if ($result !== false){
                        R('Log/add',array('accountSetting','132','账号设置',op_update,$content_sql,'解绑微信账号'));
                        $qrcodeInfo['success'] = 1;
                        $qrcodeInfo['openId'] = $userName;
                        $unbindId = $unbindId['id'];
                        $unbind->where("id=$unbindId")->save($qrcodeInfo);
                        WeixinApi::sendServiceMsg($userName, "text", "恭喜您解绑成功，可随时开启绑定哦");
                    }else{
                        $qrcodeInfo['success'] = 2;
                        $qrcodeInfo['openId'] = $userName;
                        $unbindId = $unbindId['id'];
                        $unbind->where("id=$unbindId")->save($qrcodeInfo);
                        WeixinApi::sendServiceMsg($userName, "text", "解绑失败请重试");
                    }
                }else{
                    $qrcodeInfo['success'] = 1;
                    $qrcodeInfo['openId'] = $userName;
                    $unbindId = $unbindId['id'];
                    $unbind->where("id=$unbindId")->save($qrcodeInfo);
                    WeixinApi::sendServiceMsg($userName, "text", "验证微信号成功");
                }

            }
        }else{
            $qrcodeInfo['success'] = 4;
            $qrcodeInfo['openId'] = $userName;
            $unbindId = $unbindId['id'];
            $unbind->where("id=$unbindId")->save($qrcodeInfo);
            WeixinApi::sendServiceMsg($userName, "text", "您不是此账号绑定者，无权解绑此账号");
        }
    }

    public function QrUrl($params){
        $uid = $params->uid;
        $scanId = $params->scanId;
        $cid = $params->cid;
        $userName = $params->userName;
        self::writeScanLog($scanId, '', $userName,1);
    }


}